﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TeacherManageContent.aspx.cs"
	Inherits="CourseManager.View.Contents.Admin.TeacherManageContent" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>教师管理</title>
	<script type="text/javascript">
		function DoCommand(command, id, name, dept, sex) {
			if (command == "Update") {
				DoUpdate(id, name, sex, dept);
				return;
			}
			if (command == "Delete") {
				DoDelete(id, name);
				return;
			}
			if (command == "ResetPassword") {
				DoResetPassword(id, name);
				return;
			}
		}

		function DoResetPassword(id, name) {
			Ext.Msg.confirm('系统提示', '确定要恢复教师:' + name + '的密码？初始密码为教师号', function (btn) {
				if (btn == 'yes') {
					Ext.net.DirectMethods.ResetPassword(id, {
						eventMask: {
							showMask: true,
							minDely: 200,
							msg: "请稍候......"
						}
					});
				}
			});
		}

		function DoUpdate(id, name, sex, dept) {
			Ext.net.DirectMethods.ShowUpdateWindow(id, name, sex, dept, {
				success: function (result) {
				}
			});

		}

		function DoDelete(id, name) {
			Ext.Msg.confirm('系统提示', '确定要删除教师:' + name + '？', function (btn) {
				if (btn == 'yes') {
					Ext.net.DirectMethods.DeleteTeacher(id, {
						eventMask: {
							showMask: true,
							minDely: 200,
							msg: "请稍候......"
						}
					});
				}
			});
		}

	</script>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<ext:ResourceManager runat="server" />
		<ext:Store runat="server" ID="TeacherStore">
			<Reader>
				<ext:JsonReader>
					<Fields>
						<ext:RecordField Name="teacherId" />
						<ext:RecordField Name="name" />
						<ext:RecordField Name="dept" />
						<ext:RecordField Name="sex" />
						<ext:RecordField Name="password" />
					</Fields>
				</ext:JsonReader>
			</Reader>
		</ext:Store>
		<ext:Viewport runat="server" Layout="Fit">
			<Items>
				<ext:Panel runat="server" Header="false" Border="false" Layout="border">
					<TopBar>
						<ext:Toolbar runat="server">
							<Items>
								<ext:Button runat="server" Icon="Add" ID="btnOpenSearch" ToolTip="添加" Text="添加" Visible="true">
									<Listeners>
										<Click Handler="#{AddWindow}.show();" />
									</Listeners>
								</ext:Button>
								<ext:ToolbarSpacer Width="370" />
								<ext:TextField runat="server" ID="txtKeyword" Width="150" MaxLength="20" EmptyText="搜索关键字" />
								<ext:Button runat="server" ID="btnSearch" Text="查询" Icon="YcZoomClassic" Width="55">
									<DirectEvents>
										<Click OnEvent="BtnSearchClick">
											<EventMask ShowMask="true" Msg="正在查询，请稍候..." />
										</Click>
									</DirectEvents>
								</ext:Button>
							</Items>
						</ext:Toolbar>
					</TopBar>
					<Items>
						<ext:GridPanel runat="server" Header="true" Border="false" Title="用户管理"
							StoreID="TeacherStore" StripeRows="true" EnableColumnMove="false" EnableColumnHide="false"
							EnableHdMenu="false" Region="Center">
							<ColumnModel>
								<Columns>
									<ext:RowNumbererColumn />
									<ext:Column ColumnID="colId" Header="ID" Width="80" DataIndex="teacherId" Sortable="false" Align="Center" />
									<ext:Column ColumnID="colName" Header="姓名" Width="70" DataIndex="name" Align="Center" />
									<ext:Column ColumnID="colDept" Header="学院" Width="80" DataIndex="dept"  Align="Center"/>
									<ext:Column ColumnID="colSex" Header="性别" Width="40" DataIndex="sex" Align="Center" />
									<ext:Column ColumnID="colPassword" Header="密码(MD5)" Width="260" DataIndex="password" Align="Center" />
									<ext:CommandColumn Width="70" Header="操作">
										<Commands>
											<ext:GridCommand Icon="PageWhiteEdit" CommandName="Update" ToolTip-Text="修改" />
											<ext:GridCommand Icon="KeyGo" CommandName="ResetPassword" ToolTip-Title="还原默认密码" />
											<ext:GridCommand Icon="Delete" CommandName="Delete" ToolTip-Title="删除" />
										</Commands>
									</ext:CommandColumn>
								</Columns>
							</ColumnModel>
							<SelectionModel>
								<ext:RowSelectionModel runat="server" SingleSelect="true" />
							</SelectionModel>
							<Listeners>
								<Command Handler="DoCommand(command,record.data.teacherId, record.data.name, record.data.dept, record.data.sex);" />
							</Listeners>
							<LoadMask ShowMask="true" Msg="正在加载，请稍候..." />
							<BottomBar>
								<ext:PagingToolbar ID="pagingBar" runat="server" PageSize="15" DisplayInfo="true"
									RefreshText="刷新" StoreID="TeacherStore">
									<Items>
										<ext:ToolbarSpacer runat="server" Width="10" />
										<ext:Label runat="server" Text="每页显示:" />
										<ext:ToolbarSpacer runat="server" Width="10" />
										<ext:ComboBox runat="server" Width="80" Editable="false">
											<Items>
												<ext:ListItem Text="10" />
												<ext:ListItem Text="15" />
												<ext:ListItem Text="20" />
												<ext:ListItem Text="25" />
											</Items>
											<SelectedItem Value="15" />
											<Listeners>
												<Select Handler="#{pagingBar}.pageSize = parseInt(this.getValue()); #{pagingBar}.doLoad();" />
											</Listeners>
										</ext:ComboBox>
										<ext:ToolbarSpacer runat="server" Width="10" />
										<ext:Label runat="server" Text="条记录" />
									</Items>
								</ext:PagingToolbar>
							</BottomBar>
						</ext:GridPanel>
					</Items>
				</ext:Panel>
			</Items>
		</ext:Viewport>
		<ext:Window runat="server" ID="AddWindow" Width="300" Height="200" Title="添加教师" Icon="YcGroupMembers"
			Layout="Fit" Hidden="true" Frame="true" Resizable="false" Modal="true" BodyStyle="background-color:transparent;">
			<Items>
				<ext:FormPanel runat="server"  Border="false" Padding="5" AutoScroll="true"
					LabelAlign="Left" LabelWidth="80" Frame="true">
					<Items>
						<ext:TextField runat="server" ID="txtAddId" FieldLabel="教师号" Width="140" MaxLength="100"
							AllowBlank="false" InvalidText="*" Margins="side" ReadOnly="false" BlankText="请输入用户名" />
						<ext:TextField runat="server" ID="txtAddName" FieldLabel="姓名" Width="140" MaxLength="10" />
						<ext:ComboBox runat="server" ID="cbAddSex" FieldLabel="性别" Width="50" Editable="false"
							SelectOnFocus="true" ClearButton="true" BlankText="请选择性别">
							<Items>
								<ext:ListItem Text="男" Value="男" />
								<ext:ListItem Text="女" Value="女" />
							</Items>
						</ext:ComboBox>
						<ext:TextField runat="server" ID="txtAddDept" FieldLabel="院系" Width="140" MaxLength="20" />
					</Items>
					<Buttons>
						<ext:Button runat="server" Text="确定" ID="BtnAddOk" Icon="accept">
							<Listeners>
								<Click Handler="if (!#{txtAddId}.validate()) { return false;}" />
							</Listeners>
							<DirectEvents>
								<Click OnEvent="BtnAddOkClick">
									<EventMask ShowMask="true" Msg="正在添加.." />
								</Click>
							</DirectEvents>
						</ext:Button>
						<ext:Button runat="server" Text="取消" ID="Button2" Icon="YcDeclineTask">
							<Listeners>
								<Click Handler="#{AddWindow}.hide();" />
							</Listeners>
						</ext:Button>
					</Buttons>
				</ext:FormPanel>
			</Items>
		</ext:Window>
		
		<ext:Window runat="server" ID="UpdateWindow" Width="300" Height="200" Title="修改教师信息" Icon="YcGroupMembers"
			Layout="Fit" Hidden="true" Frame="true" Resizable="false" Modal="true" BodyStyle="background-color:transparent;">
			<Items>
				<ext:FormPanel runat="server"  Border="false" Padding="5" AutoScroll="true"
					LabelAlign="Left" LabelWidth="80" Frame="true">
					<Items>
						<ext:TextField runat="server" ID="txtUpdateId" FieldLabel="教师号" Width="140" MaxLength="100"
							AllowBlank="false" Disabled="true" InvalidText="*" Margins="side" ReadOnly="false" BlankText="请输入用户名" />
						<ext:TextField runat="server" ID="txtUpdateName" FieldLabel="姓名" Width="140" MaxLength="10" />
						<ext:ComboBox runat="server" ID="cbUpdateSex" FieldLabel="性别" Width="50" Editable="false"
							SelectOnFocus="true" ClearButton="true" BlankText="请选择性别">
							<Items>
								<ext:ListItem Text="男" Value="男" />
								<ext:ListItem Text="女" Value="女" />
							</Items>
						</ext:ComboBox>
						<ext:TextField runat="server" ID="txtUpdateDept" FieldLabel="院系" Width="140" MaxLength="20" />
					</Items>
					<Buttons>
						<ext:Button runat="server" Text="确定" ID="Button1" Icon="accept">
							<Listeners>
								<Click Handler="if (!#{txtUpdateId}.validate()) { return false;}" />
							</Listeners>
							<DirectEvents>
								<Click OnEvent="BtnUpdateOkClick">
									<EventMask ShowMask="true" Msg="正在更新.." />
								</Click>
							</DirectEvents>
						</ext:Button>
						<ext:Button runat="server" Text="取消" ID="Button3" Icon="YcDeclineTask">
							<Listeners>
								<Click Handler="#{UpdateWindow}.hide();" />
							</Listeners>
						</ext:Button>
					</Buttons>
				</ext:FormPanel>
			</Items>
		</ext:Window>
	</div>
	</form>
</body>
</html>
